package com.xiaoyu.lingdian.controller;

import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import com.xiaoyu.lingdian.tool.DateUtil;
import com.xiaoyu.lingdian.tool.StringUtil;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import com.xiaoyu.lingdian.tool.out.ResultMessageBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMethod;
import com.xiaoyu.lingdian.controller.BaseController;
import com.xiaoyu.lingdian.entity.CoreIntegral;
import com.xiaoyu.lingdian.service.CoreIntegralService;
import com.xiaoyu.lingdian.vo.CoreIntegralVO;

@Controller
@RequestMapping(value="/coreIntegral")
public class CoreIntegralController extends BaseController {

	/**
	* CoreIntegral表
	*/
	@Autowired
	private CoreIntegralService coreIntegralService;

	/**
	* 修改
	*
	* @param criglUuid 标识UUID
	* @param criglName 触发事件
	* @param criglScore 所得积分
	* @param criglDesc 说明
	* @return
	*/
	@RequestMapping(value="/update/coreIntegral", method=RequestMethod.POST)
	public void updateCoreIntegral (String criglUuid, String criglName, String criglScore, String criglDesc, HttpServletResponse response) {
		logger.info("[CoreIntegralController]:begin updateCoreIntegral");

		if (StringUtil.isEmpty(criglUuid)) {
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "[标识UUID]不能为空!"), response);
			return;
		}

		CoreIntegral coreIntegral = new CoreIntegral();
		coreIntegral.setCriglUuid(criglUuid);
		coreIntegral.setCriglName(criglName);
		coreIntegral.setCriglScore(criglScore);
		coreIntegral.setCriglDesc(criglDesc);
		coreIntegral.setCriglUdate(new Date());

		coreIntegralService.updateCoreIntegral(coreIntegral);

		writeAjaxJSONResponse(ResultMessageBuilder.build(true, 1, "修改成功!"),response);
		logger.info("[CoreIntegralController]:end updateCoreIntegral");
	}

	/**
	* 获取单个
	*
	* @param criglUuid 标识UUID
	* @return
	*/
	@RequestMapping(value="/views", method=RequestMethod.POST)
	public void viewsCoreIntegral (String criglUuid, HttpServletResponse response) {
		logger.info("[CoreIntegralController]:begin viewsCoreIntegral");

		if (StringUtil.isEmpty(criglUuid)) {
			writeAjaxJSONResponse(ResultMessageBuilder.build(false, -1, "[标识UUID]不能为空!"), response);
			return;
		}

		CoreIntegral coreIntegral = new CoreIntegral();
		coreIntegral.setCriglUuid(criglUuid);

		coreIntegral = coreIntegralService.getCoreIntegral(coreIntegral);

		CoreIntegralVO coreIntegralVO = new CoreIntegralVO();
		coreIntegralVO.convertPOToVO(coreIntegral);

		writeAjaxJSONResponse(ResultMessageBuilder.build(true, 1, "获取单个信息成功", coreIntegralVO), response);
		logger.info("[CoreIntegralController]:end viewsCoreIntegral");
	}

	/**
	* 获取列表<List>	
	* @return
	*/
	@RequestMapping(value="/find/all", method=RequestMethod.POST)
	public void findCoreIntegralList (HttpServletResponse response) {
		logger.info("[CoreIntegralController]:begin findCoreIntegralList");

		List<CoreIntegral> lists = coreIntegralService.findCoreIntegralList();
		List<CoreIntegralVO> vos = new ArrayList<CoreIntegralVO>();
		CoreIntegralVO vo;
		for (CoreIntegral coreIntegral : lists) {
			vo = new CoreIntegralVO();

			vo.setCriglUuid(coreIntegral.getCriglUuid());
			vo.setCriglName(coreIntegral.getCriglName());
			vo.setCriglScore(coreIntegral.getCriglScore());
			vo.setCriglDesc(coreIntegral.getCriglDesc());
			vo.setCriglCdate(DateUtil.formatTimesTampDate(coreIntegral.getCriglCdate()));
			vo.setCriglUdate(DateUtil.formatTimesTampDate(coreIntegral.getCriglUdate()));

			vos.add(vo);
		}
		writeAjaxJSONResponse(ResultMessageBuilder.build(true, 1, "list列表获取成功!", vos),response);
		logger.info("[CoreIntegralController]:end findCoreIntegralList");
	}

//<=================定制内容开始==============
//==================定制内容结束==============>

}
